/*
 * FileName: StaffDailyDao.java
 *
 */
package com.mrc.ak.daily.dao;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.mrc.ak.daily.model.DailyInfo;
import com.mrc.core.base.BaseDao;
import com.mrc.core.base.PageDatas;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author Mrc
 * @version 4.1

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2016-12-22 上午10:18:25          Mrc        4.1         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Repository
public class DailyInfoDao extends BaseDao<DailyInfo> {

    /**
     * @param entityClass
     */
    protected DailyInfoDao() {
        super(DailyInfo.class);
    }

    public DailyInfo findByMobile(String userMobile) {
        List<DailyInfo> list = super.queryHQL(" from DailyInfo u where u.mobile=?", userMobile);
        return list.size() > 0 ? list.get(0) : null;
    }

    /**
     * 按照条件查询日报
     * @param date  2016-12-22 或者  2016-12-21至2016-12-22
     * @param verifyStatus
     * @param type
     * @return
     */
    public PageDatas query(String date, String verifyStatus, Integer type, Integer pageNo, Integer pageSize) {
        StringBuilder sql = new StringBuilder("select * from ak_daily_info where 1=1 ");
        if (StringUtils.isNotEmpty(verifyStatus))
            sql.append(" and verify_status =" + verifyStatus);
        if (type != null && type == 2)
            sql.append(" and type =" + type);
        if (StringUtils.isNotEmpty(date)) {
            String[] dateArr = date.split("至");
            sql.append(" and create_date between '").append(dateArr[0]).append(" 00:00:00' and '").append(dateArr.length > 1 ? dateArr[1] : dateArr[0]).append(" 23:59:59' ");
        }
        return super.querySQL(sql.toString(), pageNo, pageSize);
    }

}
